package com.ryder.petmatediarybackend.module.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ryder.petmatediarybackend.module.auth.entity.SysPermission;
import com.ryder.petmatediarybackend.module.auth.mapper.SysPermissionMapper;
import com.ryder.petmatediarybackend.module.auth.service.SysPermissionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述：权限表(SysPermission)表服务实现类
 *
 * @author Ryder
 * @version 1.0
 * @since 1.0
 * 更新日期: 2025/10/26
 */
@Service("sysPermissionService")
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {

    @Override
    public List<SysPermission> listAllPermissions() {
        return this.list();
    }

    @Override
    public SysPermission getByCode(String code) {
        LambdaQueryWrapper<SysPermission> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysPermission::getCode, code);
        return this.getOne(wrapper);
    }

    @Override
    public boolean existsByCode(String code) {
        LambdaQueryWrapper<SysPermission> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysPermission::getCode, code);
        return this.count(wrapper) > 0;
    }
}
